package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.SecondKillsDao;
import org.ysu.shoeShopping.entity.SecondKills;
import org.ysu.shoeShopping.service.SecondKillsService;

import javax.annotation.Resource;

/**
 * 秒杀表(SecondKills)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:33
 */
@Service("secondKillsService")
public class SecondKillsServiceImpl implements SecondKillsService
{
    @Resource
    private SecondKillsDao secondKillsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param skid 主键
     * @return 实例对象
     */
    @Override
    public SecondKills queryById(Integer skid) {
        return this.secondKillsDao.queryById(skid);
    }

    /**
     * 分页查询
     *
     * @param secondKills 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SecondKills> queryByPage(SecondKills secondKills, PageRequest pageRequest) {
        long total = this.secondKillsDao.count(secondKills);
        return new PageImpl<>(this.secondKillsDao.queryAllByLimit(secondKills, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param secondKills 实例对象
     * @return 实例对象
     */
    @Override
    public SecondKills insert(SecondKills secondKills) {
        this.secondKillsDao.insert(secondKills);
        return secondKills;
    }

    /**
     * 修改数据
     *
     * @param secondKills 实例对象
     * @return 实例对象
     */
    @Override
    public SecondKills update(SecondKills secondKills) {
        this.secondKillsDao.update(secondKills);
        return this.queryById(secondKills.getSkid());
    }

    /**
     * 通过主键删除数据
     *
     * @param skid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer skid) {
        return this.secondKillsDao.deleteById(skid) > 0;
    }
}
